package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * tiger
 * 商品
 */

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class Product extends BaseDomain {
    public static final Integer STATE_COMMON = 0;//上架
    public static final Integer STATE_HOT = 1;//推荐
    public static final Integer STATE_DISABLED = -1;//下架

    //商品名称
    private String title;
    //商品价格
    private BigDecimal price;
    //商品图片
    private String imgUrl;
    //商品分类
    private ProductSort sort;
    //商品状态
    private Integer state;
    //商品详情
    private ProductContent productContent;
    //商品规格
    private List<ProductSpecs> productSpecs = new ArrayList<>();

    //商品数量 lituan
    private Long count;

    //商品型号
    private ProductSpecs specs;



    //获取状态名称
    public String getStateName() {
        String stateName = "上架";
        if (STATE_HOT == state) {
            stateName = "推荐";
        } else if (STATE_DISABLED == state) {
            stateName = "下架";
        }
        return stateName;
    }

    //获取json对象
    public Object getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("price", price);
        map.put("imgUrl", imgUrl);
        map.put("state", state);
        if (sort != null) {
            map.put("sortId", sort.getId());
            map.put("sortName", sort.getName());
        }
        return JSONUtil.toJSONString(map);
    }

    public String[] getImgArr() {
        if (imgUrl != null) {
            String[] imgArr = imgUrl.split(";");
            return imgArr;
        }
        return null;
    }


}